package mylab.usm.oauth2.client.controller;

import com.fujieid.jap.core.JapUserService;
import com.fujieid.jap.core.config.AuthenticateConfig;
import com.fujieid.jap.core.config.JapConfig;
import com.fujieid.jap.simple.SimpleConfig;
import com.fujieid.jap.simple.SimpleStrategy;
import jakarta.annotation.Resource;
import mylab.usm.oauth2.client.config.AuthProperties;
import mylab.usm.oauth2.client.config.AuthStrategy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 简单的用户名/密码认证，不使用第三方认证服务
 * 需要依赖 jap-simple 模块
 */
@RestController
@RequestMapping("/simple")
public class SimpleController extends BaseAuthController<SimpleStrategy> {

    @Resource(name = "simple")
    private JapUserService japUserService;

    @Override
    protected AuthStrategy getAuthStrategy() {
        return AuthStrategy.simple;
    }

    @Override
    protected JapUserService getUserService() {
        return japUserService;
    }

    @Override
    protected SimpleStrategy getJapStrategy(JapUserService japUserService, JapConfig japConfig) {
        return new SimpleStrategy(japUserService, japConfig);
    }

    @Override
    protected AuthenticateConfig getAuthenticateConfig(AuthProperties.Platform platform) {
        return new SimpleConfig()
                .setRememberMeCookieDomain(properties.getDomain());
    }

}
